﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.Packets
{
    public enum DisconnectRaison
    {
        DeclinedByDestination = 1,
        DeclinedByProvider
    }
    public class DisconnectionPacket : Packet
    {
        private byte adresseSource;
        private byte adresseDestination;
        private byte raison;

        private DisconnectionPacket(byte numeroConnexion, byte typePacket, byte adresseSource, byte adresseDestination, byte raison)
        {
            this.numeroConnexion = numeroConnexion;
            this.typePacket = typePacket;
            this.adresseSource = adresseSource;
            this.adresseDestination = adresseDestination;
            this.raison = raison;
        }

        public byte AdresseSource { get { return adresseSource; } }
        public byte AdresseDestination { get { return adresseDestination; } }

        public static DisconnectionPacket CreateFreeConnectionPacket(int numeroConnexion, int adresseSource, int adresseDestination, DisconnectRaison raison)
        {
            DisconnectionPacket requestPacket = new DisconnectionPacket(Convert.ToByte(numeroConnexion), 
                                                                        (byte)PacketTypes.FreeConnectionPacket, 
                                                                        Convert.ToByte(adresseSource), 
                                                                        Convert.ToByte(adresseDestination),
                                                                        (byte)raison);
            return requestPacket;
        }

        public void CreatePacketFromCharOfBitArray()
        {

        }

        public override string GetStringOfBitArray()
        {
            //numeroConnexion = 3;
            //adresseSource = 34;
            //adresseDestination = 56;
            //raison = (byte)DisconnectRaison.DeclinedByDestination;

            string arrayOfBits = base.GetStringOfBitArray();
            arrayOfBits += Convert.ToString(adresseSource, 2).PadLeft(8, '0');
            arrayOfBits += Convert.ToString(adresseDestination, 2).PadLeft(8, '0');
            arrayOfBits += Convert.ToString(raison, 2).PadLeft(8, '0');
            return arrayOfBits;
        }
    }
}
